<?php
class Category_model extends CI_Model{
    var $table = 'category';
    function add_category($data)
    {
        if(!empty($data['id']))
        {
            $str = 'UPDATE `'.$this->table.'` SET title = "'.$this->db->escape_str(strip_tags($data['title'])).'", 
            parent_id = "'.$data['parent_id'].'" WHERE id = "'.$data['id'].'"';
        }else{
            $str = 'INSERT INTO "'.$this->table.'"("title","parent_id") VALUES("'.$this->db->escape_str(strip_tags($data['title'])).'", "'.$data['parent_id'].'")';
        }
        
        $this->db->query($str);
    }
    
    function remove_category($id)
    {
        $str = 'DELETE FROM `'.$this->table.'` WHERE id = "'.$id.'"';
        $this->db->query($str);
    }
    
    function get_list_category()
    {
        $query = $this->db->get($this->table);
        return $query->result_object();
    }
    
    function get_item($id)
    {
        $query = $this->db->get_where($this->table,array('id' => $id));
        return $query->row_object(0);
    }
}
?>